package vista;

import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.List;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JPanel;
/**
 * this class will create the suspects sheet zone
 * @author Jose Luis Garcia && Alvaro Blazquez Checa
 *
 */
public class SuspectAreaFiller extends JPanel{
	
	BufferedImage imagenFondo;
	Icon imagenMarcado;
	List<JButton> botonera;
	
	/**
	 * this constructor will instantiate the suspect sheet
	 * @param imagenMarcado the current image when you have that monk in your list
	 * @param imagenFondo the background Image
	 */
	public SuspectAreaFiller (BufferedImage imagenMarcado,BufferedImage imagenFondo){
		this.imagenFondo= imagenFondo;
		this.imagenMarcado= new ImageIcon(imagenMarcado);
		setLayout(null);
		botonera = new ArrayList<JButton>();
		initiateButtons();
		showButtons();
		hideButtons();
		//boolean inicial[]=createInitialTestBools();
		//updateSuspectSheet(inicial);
		//botonera.get(23).setVisible(true);
		
	}/**
	 * instantiate initial buttons in the panel
	 * @return
	 */
	private boolean[] createInitialTestBools() {
	  boolean array[]=new boolean[23];
	  boolean triger=false;
		for (int i=0;i<23;i++){
				if(triger==false){
					array[i]=triger;
					
					triger=true;
					System.out.println(array[i]);
				}
				else if(triger==true){
					array[i]=triger;
					
					triger=false;
					System.out.println(array[i]);
				}
				}
		return array;
	}/**
	 * this will set the butons 
	 */
	private void showButtons() {
		for(JButton boton : botonera){
			boton.setOpaque(false);
			boton.setContentAreaFilled(false);
			add(boton);
			
		}
		
	}
	/**
	 * this will let you update selected monks 
	 */
	public void updateSuspectSheet(){
		for (int i=0;i<GameLogic.suspects.length;i++)
			if(GameLogic.suspects[i])
				botonera.get(i).setVisible(true);
	}
	
	
	/**
	 * this will hide all buttons 
	 */
	private void hideButtons() {
		if(!botonera.contains(null))
		for(JButton boton : botonera){
		
			boton.setVisible(false);
		}
		
	}
	/**
	 * this will initiate buttons 
	 */
	public void initiateButtons() {
		JButton pibot;
		int x=91;
		int y=30;
		int z=30;

		
		for (int i= 0; i<24 ; i++){
			 pibot=new JButton();
			 pibot.setLayout(null);
			 pibot.setIcon(imagenMarcado);
			 
			 
			
		if (i>=0 && i<8){
				if (i==0){pibot.setBounds(30, y, imagenMarcado.getIconWidth()-3
						,imagenMarcado.getIconHeight()-1);
				
				pibot.setVisible(true);	
				botonera.add(pibot);
				//add(pibot);
				}
				
				else
					{
					
					pibot.setBounds(y+imagenMarcado.getIconWidth()-3,30 ,imagenMarcado.getIconWidth()-3
							,imagenMarcado.getIconHeight()-1);
					
					pibot.setVisible(true);
					botonera.add(pibot);
					//add(pibot);
					y=y+imagenMarcado.getIconWidth()-3;
				}
		}
		else
			if(i==8)y=z;
		if (i>=8 && i<16){
			
			if (i==8){
					pibot.setBounds(y,30+imagenMarcado.getIconHeight()-1 ,imagenMarcado.getIconWidth()-3
					,imagenMarcado.getIconHeight()-1);	
					pibot.setVisible(true);
					botonera.add(pibot);
			//		add(pibot);
				
			
			}
			else{
			
				pibot.setBounds(y+imagenMarcado.getIconWidth()-3,30+imagenMarcado.getIconHeight()-1,imagenMarcado.getIconWidth()-3
						,imagenMarcado.getIconHeight()-1);
				pibot.setVisible(true);
				botonera.add(pibot);
				//add(pibot);
				y=y+x;
			}
		}
			else if(i==16)
				y=z;
			if(i>=16 && i<24){
				if (i==16){
					pibot.setBounds(y,(imagenMarcado.getIconHeight()+11)*2 ,imagenMarcado.getIconWidth()-3
					,imagenMarcado.getIconHeight()-1);	
					pibot.setVisible(true);
					botonera.add(pibot);
//					add(pibot);
				
			
			}
				else{
				
					pibot.setBounds(y+imagenMarcado.getIconWidth()-3,(imagenMarcado.getIconHeight()+11)*2,imagenMarcado.getIconWidth()-3
							,imagenMarcado.getIconHeight()-1);
					pibot.setVisible(true);
					botonera.add(pibot);
//					add(pibot);
					y=y+imagenMarcado.getIconWidth()-3;
				}
			}
		}//for
		
		
		
	}
	/**
	 * method to set background image
	 */
	public void paintComponent(Graphics g) {
		if (imagenFondo != null) {
			g.drawImage(imagenFondo, 0, 0,  imagenFondo.getWidth(),imagenFondo.getHeight(), null);
		}
	}
}
